package com.niit.galcomment.service.impl;

import com.niit.dao.MpDao;
import com.niit.dao.SpDao;
import com.niit.entity.Mp;
import com.niit.entity.Sp;
import com.niit.galcomment.service.CommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class CommentServiceImpl implements CommentService {
    @Resource
    private MpDao mpDao;
    @Resource
    private SpDao spDao;

    @Override
    public Mp findMp(int tid) {
        return mpDao.queryById(tid);
    }

    @Override
    public Sp findSp(int htid) {
        return spDao.queryById(htid);
    }

    @Override
    public void deleteMp(int tid) {
        spDao.deleteByTid(tid);
        mpDao.deleteById(tid);
    }

    @Override
    public void deleteSp(int htid) {
        Sp sp = spDao.queryById(htid);
        mpDao.deleteReply(sp.getTid());
        spDao.deleteById(htid);
    }

    @Override
    public List<Mp> findByGid(int gid) {
        return mpDao.queryByGid(gid);
    }

    @Override
    public List<Sp> findSpByMp(int tid) {
        return spDao.queryByTid(tid);
    }

    @Override
    public int insetMp(Mp mp) {
        return mpDao.insert(mp);
    }

    @Override
    public void insetSp(Sp sp) {
        spDao.insert(sp);
        mpDao.addReply(sp.getTid());
    }

    @Override
    public void upvoteMp(int tid) {
        mpDao.upvote(tid);
    }

    @Override
    public void upvoteSp(int htid) {
        spDao.upvote(htid);
    }
}
